package com.icss.controller;

import com.icss.domain.User;
import com.icss.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
   @Autowired
   private UserService userService;

    @RequestMapping("list")
    public String list(){
        return "list";
    }

    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<User> userList = userService.findAll();
        model.addAttribute("userList",userList);
        return "userList";
    }
    @RequestMapping("/delete/{id}")
    public String deleteById(@PathVariable("id") Integer id, HttpServletRequest request){
     userService.deleteById(id);
     //删除以后重新回到列表页面 重定向到findall 重定向不能到视图 只能到conterollerd方法
       return "redirect:/user/findAll";
    }

}
